<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>this应用</title>
</head>
<script>
    (function () {
        'use strict';
        function Point(x, y) {
            var myself = this;
            this.x = x;
            this.y = y;
            myself.z = 12;
            console.log([this, this.x, this.y, this.z]);
        }

        Point.prototype.getX = function () {
            return this.x;
        }

        Point.prototype.doTest = function () {
            function fn(){
                console.log(["嵌套", this, self, myself]);
            }
            fn();
        }

        var pt = new Point(1, 2);
        console.log(pt.getX());
        console.log(pt);
        console.log(self);
        pt.doTest();

        var getX = Point.prototype.getX;
        console.log(getX);
        console.log(Point.prototype.getX === getX);
        //console.log(`getX() = ${getX()} `);    //this没有定义
        console.log(`getX(pt) = ${getX(pt)} `);
        console.log(`getX({x:100}) = ${getX({ x: 100 })} `);
        console.log(`getX.call({x:100}) = ${getX.call({ x: 100 })} `);

        pt.x = 50;
        console.log(`getX() = ${getX()} `);
        console.log(`pt.getX() = ${pt.getX()} `);
    }());

</script>

<body>

</body>

</html>